package com.ensibs.nuitinfo2013;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class CarouselActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.carousel);

		 final CarouselLayout layout = (CarouselLayout) findViewById(R.id.carouselLayout);
	        final CarouselAdapter adapter = new CarouselAdapter();

	        layout.setAdapter(adapter);
	        
	        //Variant 2
	        layout.setTranslate(50);
	        layout.setSpaceBetweenViews(200);
	        layout.setRotation(10);
	          
	        //Variant 3
	      /*  layout.setTranslate(50);
	        layout.setSpaceBetweenViews(100);
	        layout.setRotation(-10);*/
	        
	        //Variant 4
	       /* layout.setTranslate(-50);
	        layout.setSpaceBetweenViews(200);
	        layout.setRotation(-10);*/
	}


	 public class CarouselAdapter extends BaseAdapter {
		 
	
	        private int[] mImagesID = {
	            R.drawable.android1, 
	            R.drawable.android2, 
	            R.drawable.android3, 
	            R.drawable.android4, 
	            R.drawable.android5,
	            R.drawable.android6, 
	            R.drawable.android7, 
	            R.drawable.android8, 
	            R.drawable.android9
	        };

		 
/*		 
		 private CarouselAdapter(){
			 
		 CarouselList offerList = new CarouselList();
		 for(int i=0,i<nombre image,i++){
			 
			insert(android)
		 }
		 }*/
		 
	        @Override
	        public int getCount() {
	            return mImagesID.length;
	        }

	        @Override
	        public Object getItem(int position) {
	            return mImagesID[position];
	        }
	        
	 

	        @Override
	        public long getItemId(int position) {
	            return position;
	        }

	        @Override
	        public View getView(int position, View convertView, ViewGroup parent) {
	            if ((position < 0) && (position > (getCount() - 1))) {
	                Log.e("UITEST", "Unexistent position requested");

	                return null;
	            }

	            ImageView imageView;
	            if (convertView != null) {
	                imageView = (ImageView) convertView;

	            } else {            	
	                imageView = new ImageView(getApplicationContext());
	                imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
	              //Layout params must be FILL_PARENT
	                imageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
	            }
	            imageView.setImageResource(mImagesID[position]);

	            return imageView;
	        }

}
	 
	/* 
	 
	 public class CarouselList implements List{
			
			private Element current;
			private Element sentinel;
			private int size;

			private class Element{
				
				
				private Element prev, next;
				private Object theValue;

				public Element(){};

				public Element(Element p, Object data, Element n){
					prev=p; theValue=data; next=n;

				}
			}
			
			public CarouselList(){
				sentinel=new Element();
				sentinel.next=sentinel;
				sentinel.prev=sentinel;
				current=sentinel;
			}
			

			public boolean next(){
				boolean ret=true;
				if(current.next != sentinel)
					current=current.next;
				else
					ret=false;
				return ret;
			}
			
			public boolean previous(){
				boolean ret=true;
				if(current.prev != sentinel)
					current=current.prev;
				else
					ret=false;
				return ret;
			}
			
			public String toString(){
				Element tmp;
				String ret="[";
				
				tmp=sentinel.next;
				
				while(tmp != sentinel){
					ret+=tmp.theValue.toString();
					if(tmp.next != sentinel)
						ret+=", ";
					tmp=tmp.next;
				}
				
				ret+="]";
				
				return ret;
			}
			
			public Object getValueAt(int index){
				Object ret=null;
				Element tmp;
				
				if((index < size) && (index >= 0)){
					tmp=sentinel.next;
					for(int i=0;i<index;i++)
						tmp=tmp.next;
					ret=tmp.theValue;
				}
				
				return ret;
			}
			

			
			
			
			public void insert(Object data){
				Element e=new Element(current, data, current.next);
				current.next=e;
				e.next.prev=e;
				current=e;
				size++;
			}

			public void delete() {
				if(current != sentinel){
					current.prev.next=current.next;
					current.next.prev=current.prev;
					current=current.prev;
					size--;
				}
			}

			public int getSize() {
				return size;
			}
*/

	 }
 
	


